﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAWSharp.FileFormats.WavFile.Entities
{
    public class FormatHeader
    {
        public char[] formatChunkID { get; set; }
        public int formatChunkSize { get; set; }
        public short audioFormat { get; set; }
        public short numberOfChannels { get; set; }
        public int sampleRate { get; set; }
        public int byteRate { get; set; }
        public short blockAlign { get; set; }
        public short bitsPerSample { get; set; }

        public override string ToString()
        {
            return (string.Format(@"ChunkId: {0}
                                   Chunk Size: {1}            
                                   Audio Format: {2}
                                   Number of Channels: {3}
                                   Sample Rate: {4}
                                   Byte Rate: {5}
                                   Block Align: {6}
                                   Bit Depth: {7}"
                                , new string(formatChunkID)
                                , formatChunkSize.ToString()
                                , audioFormat.ToString()
                                , numberOfChannels.ToString()
                                , sampleRate.ToString()
                                , byteRate.ToString()
                                , blockAlign.ToString()
                                , bitsPerSample.ToString()));
        }

        public bool IsValid()
        {
            if (!(new string(formatChunkID) == "fmt "))
                return false;

            if (audioFormat != 1)
                return false;

            if (numberOfChannels != 1 && numberOfChannels != 2)
                return false;

            if (bitsPerSample != 16 && bitsPerSample != 24 && bitsPerSample != 32)
                return false;

            return true;
        }
    }
}
